package com.keyleaf.up.document.config;


import com.keyleaf.up.document.DocumentClient;
import com.keyleaf.up.document.handler.AbstractDocumentToPdfHandler;
import com.keyleaf.up.document.handler.DefaultToPdfHandler;
import com.keyleaf.up.document.handler.ZipToPdfHandler;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author keyleaf
 * @since 2025/5/30
 **/
@Configuration
@EnableConfigurationProperties(DocumentProperties.class)
public class DocumentAutoConfiguration {

    private final DocumentProperties documentProperties;

    public DocumentAutoConfiguration(DocumentProperties documentProperties) {
        this.documentProperties = documentProperties;
    }

    @Bean
    public AbstractDocumentToPdfHandler defaultToPdfHandler() {
        return new DefaultToPdfHandler(documentProperties.getOffice());
    }

    @Bean
    public AbstractDocumentToPdfHandler zipToPdfHandler() {
        return new ZipToPdfHandler(documentProperties.getOffice());
    }

    @Bean
    public DocumentClient documentHandler(List<AbstractDocumentToPdfHandler> handlers) {
        return DocumentClient.builder()
                .tmpDir(documentProperties.getTmpDir())
                .officeConfig(documentProperties.getOffice())
                .documentToPdfHandlers(handlers)
                .build();
    }

}
